#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "../inc/admin.h"
#include "../inc/data.h"
#include "../inc/flight_node.h"
#include "../inc/general.h"
#include "../inc/login.h"
#include "../inc/my_flight_node.h"
#include "../inc/myInfo.h"
#include "../inc/user_node.h"
#include "../inc/user.h"
#include "../inc/interface.h"
#include "./../inc/file_IO.h"

char Login_Username[20];            // 登录用户名
user_Node_p user_headNode;          // 用户链表
flight_Node_p flight_headNode;      // 航班链表
flight_Node_p airline_headNode;     // 航空公司链表
my_flight_Node_p myflight_headNode; // 用户航班记录链表

Airline_t airline[3] = {{"中国国航", 100, 80, 10}, {"东方航空", 80, 80, 10}, {"南方航空", 80, 80, 10}};

int main()
{
    int login_flag = 0; // 登录标志
    if (fopen("user.bin", "r") == NULL)
    {
        user_headNode = user_Init();
        flight_headNode = flight_Init();
        myflight_headNode = my_flight_Init();
        save_file_flight();
        save_file_my_flight();
        save_file_user();
    }

    user_headNode = load_file_user();
    flight_headNode = load_file_flight();
    myflight_headNode = load_file_my_flight();

    // airline_headNode = flightByAirline_Init(flight_headNode, "中国国航");

    clearScreen(); // 清屏
    while (1)
    {
        clearScreen();
        // 未登录
        while (login_flag == 0)
        {
            int menu; // 操作
            printf_login_menu();
            menu = *scanf_menu(&menu);
            login_flag = menuOperate_login(menu);
        }
        printf("%d\n", login_flag);
        user_Node_p userNode = find_userNode(user_headNode, Login_Username);
        if (userNode->data->user_type == 1)
        {
            airline_headNode = flightByAirline_Init(flight_headNode, find_userNode(user_headNode, Login_Username)->data->airline);
        }

        // 已登录
        clearScreen();
        while (login_flag == 10) // 10为普通用户登录，11为管理员登录
        {
            int menu; // 操作
            printf_function_menu_user();
            menu = *scanf_menu(&menu);
            login_flag = menuOperate_user(menu, login_flag);
        }
        while (login_flag == 11)
        {
            int menu; // 操作
            printf_function_menu_admin(find_userNode(user_headNode, Login_Username)->data->airline);
            menu = *scanf_menu(&menu);
            login_flag = menuOperate_admin(menu, login_flag);
        }
    }
}
